<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主要内容区main</title>
<link href="../../public/admin/css/css.css" type="text/css" rel="stylesheet" />
<link href="../../public/admin/css/main.css" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="images/main/favicon.ico" />
<style>
body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;}
#searchmain{ font-size:12px;}
#search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; width:100%; color:#FFF;float:left} 
#search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;}
#search form input.text-word{height:24px; line-height:24px; width:180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;}
#search form input.text-but{height:24px; line-height:24px; width:55px; background:url(images/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",'宋体'; color:#666; float:left; margin:8px 0 0 6px; display:inline;}
#search a.add{ background:url(images/main/add.jpg) no-repeat 0px 6px; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF}
#search a:hover.add{ text-decoration:underline; color:#d2e9ff;}
#main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;}
#main-tab th{ font-size:12px; background:url(images/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;}
#main-tab td{ font-size:12px; line-height:40px;}
#main-tab td a{ font-size:12px; color:#548fc9;}
#main-tab td a:hover{color:#565656; text-decoration:underline;}
.bordertop{ border-top:1px solid #ebebeb}
.borderright{ border-right:1px solid #ebebeb}
.borderbottom{ border-bottom:1px solid #ebebeb}
.borderleft{ border-left:1px solid #ebebeb}
.gray{ color:#dbdbdb;}
td.fenye{ padding:10px 0 0 0; text-align:right;}
.bggray{ background:#f9f9f9}
#addinfo{ padding:0 0 10px 0;}
</style>
</head>



<body>
<!--main_top-->
<table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain">
  <tr>
    <td width="99%" align="left" valign="top" id="addinfo">您的位置：帖子列表</td>
  </tr>
  
    <tr>
    <td align="left" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="search">
  		<tr>
   		 <td width="90%" align="left" valign="middle">
	         <form method="get" action="./post_message.php">
	         <span>帖子名：</span>
	         <input type="text" name="title" value="<?php echo !empty($_POST['title']) ? $_POST['title'] : ''?>" class="text-word">
	         <input  type="submit" value="查询" class="text-but">
	         </form>
         </td>
  		  <td width="10%" align="center" valign="middle" style="text-align:right; width:150px;">
  		</tr>
	</table>
    </td>
  </tr>

  <tr>
    <td align="left" valign="top">
	
	 <table width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab">
      <tr>
        <th align="center" valign="middle" class="borderright">编号</th>
        <th align="center" valign="middle" class="borderright">主题</th>
  		<th align="center" valign="middle" class="borderright">发帖人</th>
        <th align="center" valign="middle" class="borderright">发表时间</th>
        <th align="center" valign="middle" class="borderright">状态</th>
        <th align="center" valign="middle">操作</th>
      </tr>
    
		
	<?php
		//判断用户是否输入，是否要查询
		if(!empty($_POST['title'])){
			//给sql语句用的
			$where = " and title like '%{$_POST['title']}%'";
			
			$whereTitle = '';

			//url地址用的
			$urlWhere = '';		
		}
		else{
			//声明一个变量用来存SQL语句搜索条件
			$where = " user.id=post.uid and title like '%{$_GET['sTitle']}%' ";
						
			$urlWhere = "&userName=".$_GET['userName'];
			
			
			//给url地址用的
			$urlWhere = "&title=".$_GET['sTitle']; 
		}
		
		
		//每页显示多少条
		$page = 10 ;
		
		//定义当前页面是第几页，默认从1开始
		$nowPage = isset($_GET['page']) ? $_GET['page'] : 1;
		
		//每页从多少条开始
		$startPage = ($nowPage - 1) * $page;
		
		//limit返回多少行数据  定义每一页从第几条开始显示，一共显示多少条
		$limit = " limit {$startPage},{$page}";
		
		
		//连库
		mysql_connect('localhost','root','');
		
		//选库
		mysql_select_db('lamp111');
		
		mysql_set_charset('utf8');
		
		//写sql语句
		$sql = "select post.id as postId,post.title,post.ctime,post.elite,post.top,user.UserName as userName from post,user where recycle=0".$where.$limit;
		
		
		var_dump($sql);
		//var_dump($sql);
		//执行
		$result = mysql_query($sql);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
		
		//处理结果                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
		$num = $startPage + 1;
		
		//定义数组管理权限
		$status = array(0=>'普通',1=>'加精');
		$auth = array(0=>'普通',1=>'置顶');
		
		//处理结果集
		while($array = mysql_fetch_assoc($result)){
			$postStatus = '';
			if($array['elite']==='1' && $array['top'] ==='1'){
				$postStatus = '精华、置顶';
			}else if($array['elite'] ==='1' && $array['top'] ==='0'){
				$postStatus = '精华';
			}else if($array['elite'] ==='0' && $array['top'] ==='1'){
				$postStatus = '置顶';
			}else if($array['elite'] ==='0' && $array['top'] ==='0'){
				$postStatus = '普通';
			}			
		
	  ?>
	    
      <tr onMouseOut="this.style.backgroundColor='#ffffff'" onMouseOver="this.style.backgroundColor='#edf5ff'">
        <td align="center" valign="middle" class="borderright borderbottom"><?php echo $num ?></td>
        <td align="center" valign="middle" class="borderright borderbottom"><?php echo $array['title']?></td>
        <td align="center" valign="middle" class="borderright borderbottom"><?php echo $array['userName'] ?></td>
        <td align="center" valign="middle" class="borderright borderbottom"><?php echo date('Y-m-d H:i:s',$array['ctime']) ?></td>
        <td align="center" valign="middle" class="borderright borderbottom"><?php echo $postStatus ?></td>
        <td align="center" valign="middle" class="borderbottom">
		<a href="./post_replay.php?id=<?php echo $array['postId'] ?>" target="mainFrame" onFocus="this.blur()" class="add">查看贴子</a>
		<span class="gray">&nbsp;|&nbsp;</span>
		<a href="./post_messageUpdate.php?id=<?php echo $array['postId'] ?>" target="mainFrame" onFocus="this.blur()" class="add">编辑</a>
		<span class="gray">&nbsp;|&nbsp;</span>  
		<a href="./post_delete.php?id=<?php echo $array['postId'] ?>" target="mainFrame" onFocus="this.blur()" class="add">删除</a>
		<span class="gray">&nbsp;|&nbsp;</span>
		<a href="./post_dorecover.php?id=<?php echo $array['postId'] ?>" target="mainFrame" onFocus="this.blur()" class="add">放入回收站</a>
		<span class="gray">&nbsp;|&nbsp;</span>
		<a href="./post_jiajing.php?id=<?php echo $array['id'] ?>&elite=<?php echo $array['elite'] ?>" target="mainFrame" onFocus="this.blur()" class="add"><?php echo $array['elite']==0 ? '加精' : '取消加精'  ?></a>
			<span class="gray">&nbsp;|&nbsp;</span>
			<a href="./post_top.php?id=<?php echo $array['id'] ?>&top=<?php echo $array['top'] ?>" target="mainFrame" onFocus="this.blur()" class="add"><?php echo $array['top']==0 ? '置顶' : '取消置顶'  ?></a>
			<span class="gray">&nbsp;|&nbsp;</span>
		<a href="add.html" target="mainFrame" onFocus="this.blur()" class="add">管理回复</a>
      </tr>
<?php
			$num++;
		}
?>
    </table></td>
    </tr>
  <?php
				
		
		//根据情况来选择上一页和下一页
		//判断上一页，最小的页数是一
		if($nowPage > 1){
			$prevPage = $nowPage - 1;
		}
		else{
			$prevPage = 1;
		}
		
		
		//判断下一页，最大的页数是多少    //要判断最大页数我要先知道有多少页
		
		if(empty($whereTitle)){
			$countPage = "select count(post.id) as count,user.id from post,user where recycle=0".$where;
		}else{
			$countPage = "select count(post.id) as count,user.id from post,user where recycle=0".$where;
		}
		
		echo 12;
		var_dump($countPage);
		//执行语句
		$countResult = mysql_query($countPage);

		//总数   每次执行一行
		$counts = mysql_fetch_assoc($countResult)['count'];
		var_dump($counts);
		//算出最大有多少页
		$totalPage = ceil($counts / $page);
		
	
		
		//计算下一页 页码   
		//如果当前页  小于  最大页数
		if($nowPage < $totalPage){
			$nextPage = $nowPage + 1;
		}
		else{
			$nextPage = $totalPage;
		}
		
  ?>  
 <tr>
    <td align="left" valign="top" class="fenye">
		<?php echo $counts ?> 条数据<?php echo $nowPage.'/'.$totalPage ?>页&nbsp;&nbsp;
		<a href="post_message.php?page=1<?php echo $urlWhere; ?>" target="mainFrame" onFocus="this.blur()">首页</a>
		&nbsp;&nbsp;
		<a href="post_message.php?page=<?php echo $prevPage.$urlWhere ?>" target="mainFrame" onFocus="this.blur()">上一页</a>
		&nbsp;&nbsp;
		<a href="post_message.php?page=<?php echo $nextPage.$urlWhere ?>" target="mainFrame" onFocus="this.blur()">下一页</a>
		&nbsp;&nbsp;
		<a href="post_message.php?page=<?php echo $totalPage.$urlWhere ?>" target="mainFrame" onFocus="this.blur()">尾页</a>
	</td>
  </tr>
</table>
</body>
</html>